import 'package:date_format/date_format.dart';

class TimeUtils {
  static int getTimeStamp() {
    return DateTime.now().millisecondsSinceEpoch;
  }

  static String getFormatDate(int timeStamp) {
    int baseDayTimeStamp = 60 * 60 * 1000 * 24;
    int now = getTimeStamp();
    int day = now - baseDayTimeStamp;
    int day2 = now - baseDayTimeStamp * 2;
    int week = now - baseDayTimeStamp * 7;
    if (timeStamp >= day && timeStamp <= now) {
      return "今天 ${formatDate(DateTime.fromMillisecondsSinceEpoch(timeStamp), [
            "HH",
            ":",
            "nn",
          ])}";
    } else if (timeStamp >= day2 && timeStamp <= now) {
      return "2 天内 ${formatDate(DateTime.fromMillisecondsSinceEpoch(timeStamp), [
            "dd",
            "日 ",
            "HH",
          ])}";
    } else if (timeStamp >= week && timeStamp <= now) {
      return "一周内";
    } else {
      return formatDate(DateTime.fromMillisecondsSinceEpoch(timeStamp),
          ["yyyy", "/", "mm", "/", "dd", "/"]);
    }
  }
}
